package cn.ztelovecly.springboot.framework.base;

import cn.ztelovecly.springboot.framework.constant.SortTypeEnum;

public class BaseFindRequest<T extends Enum<T>> extends BaseRequest {

    // 页索引
    private int pageNumber = 1;
    // 页大小
    private int pageSize = 10;

    private Enum<T> sortKey;

    private SortTypeEnum sortType;

    public SortTypeEnum getSortType() {
        return sortType;
    }

    public void setSortType(SortTypeEnum sortType) {
        this.sortType = sortType;
    }

    public Enum<T> getSortKey() {
        return sortKey;
    }

    public void setSortKey(Enum<T> sortKey) {
        this.sortKey = sortKey;
    }

    //-----------getter&&setter-------------
    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    /**
     * 获取页索引。如果当前索引小于1，则回1.
     * @return
     */
    public int getPageNumber() {
        if (this.pageNumber <= 0) {
            return 1;
        }
        return this.pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    /**
     * 获得当前分页第一项的index
     * @return
     */
    public int getBeginItemIndex() {
        return ((this.getPageNumber() - 1) * this.getPageSize());
    }

    /**
     * 获得当前分页最后一项的index
     * @return
     */
    public int getEndItemIndex() {
        return this.getPageNumber() * this.getPageSize();
    }

}
